package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.CustomerReturnListGoods;
import com.atguigu.jxc.entity.SaleCount;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import com.google.gson.Gson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("customerReturnListGoods")
@Slf4j
public class CustomerReturnListGoodsController {
    @Autowired
    private CustomerReturnListGoodsService customerReturnListGoodsService;

    /**
     * 客户退货单查询（可查询条件：退货单号、客户、退款状态）
     * @param returnNumber
     * @param customerId
     * @param state
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("list")
    public Map<String,Object> list(String returnNumber, Integer customerId, Integer state, String sTime,String eTime){
        List<CustomerReturnList> list = customerReturnListGoodsService.list(returnNumber,customerId,state,sTime,eTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }


    /**
     * 退货单中的商品的信息
     * @param customerReturnListId
     * @return
     */
    @PostMapping("goodsList")
    public Map<String,Object> goodsList(Integer customerReturnListId){
        List<CustomerReturnListGoods> list = customerReturnListGoodsService.goodList(customerReturnListId);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }

    /**
     * 删除退货单
     * @param customerReturnListId
     * @return
     */
    @PostMapping("delete")
    public ServiceVO delete(Integer customerReturnListId){
        customerReturnListGoodsService.delete(customerReturnListId);
        return new ServiceVO(100,"请求成功");
    }


    /**
     * 客户退货统计
     * @param sTime
     * @param eTime
     * @param goodsTypeId
     * @param codeOrName
     * @return
     */
    @PostMapping("count")
    public String count(String sTime, String eTime, Integer goodsTypeId, String codeOrName){
        List<SaleCount> list = customerReturnListGoodsService.count(sTime,eTime,goodsTypeId,codeOrName);
        Gson gson = new Gson();
        String res = gson.toJson(list);
        log.info("---------------客户退货统计----------------");
        log.info(res);
        return res;

    }
}
